const commonjs = require('rollup-plugin-commonjs');
const nodeResolve = require('rollup-plugin-node-resolve');

const plugins = [
    [
        nodeResolve({
            // jsnext: true,
            main: true,
            browser: true,
        }),
        commonjs({
            include: 'node_modules/**',  // Default: undefined
            exclude: ['node_modules/foo/**', 'node_modules/bar/**'],  // Default: undefined
            ignoreGlobal: false,  // Default: false
            sourceMap: false,  // Default: true
            namedExports: {'vue': ['createApp']},  // Default: undefined
            ignore: ['conditional-runtime-dependency']
        }),
    ],
]

function createWatchOption(option) {
    return {
        input: option.inputUrl,
        plugins: plugins,
        external: ['electron'],
        output: {
            file: option.outputUrl,
            format: 'cjs',
            ...option.output
        },
        watch: {
            include: option.watchUrl,
            exclude: 'node_modules/**',
            ...option.watch
        },
        ...option.input

    }
}

module.exports = function createRollupWatchOption(option = {
    inputUrl: undefined,
    outputUrl: undefined,
    watchUrl:undefined,
    watch: {},
    input: {},
    output: {}
}) {
    if (Array.isArray(option)) {
        return option.map(item => {
            return createWatchOption(item)
        })
    } else {
        return createWatchOption(option)
    }
}